package com.example.xdzx.controller;

import com.aliyun.oss.OSS;
import com.example.xdzx.service.BugService;
import com.example.xdzx.utils.InitializeOssClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;

@RestController
public class BugController {
    @Autowired
    BugService bugService;
    /**
     * 新增bug反馈
     * @param userId
     * @param imformation
     * @param imageUrl
     * @param callBack
     * @return
     */
    @GetMapping("/addFeedback")
    public Map<String,Boolean> addFeedback(@RequestParam("userId")Long userId,
                                           @RequestParam("imformation")String imformation,
                                           @RequestParam("imageUrl") String imageUrl,
                                           @RequestParam("callBack")String callBack){
        Boolean isSuccess = bugService.addFeedback(userId,imformation,imageUrl,callBack);
        Map<String,Boolean> map = new HashMap<>();
        map.put("isSuccess",isSuccess);
        return map;
    }

    /**
     * 用于测试oss上传，没有问题
     * @return
     * @throws FileNotFoundException
     */
    @GetMapping("/test")
    public String test() throws FileNotFoundException {
        OSS oss = InitializeOssClient.getMyOss();
        String bucket = "xdzx-picture";
        InputStream inputStream = new FileInputStream("E:\\picture\\desk\\123.txt");
        oss.putObject(bucket,"img/test.txt",inputStream);

        return "success";
    }
}
